package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.bumptech.glide.Glide;

public class login11 extends AppCompatActivity {

    private EditText username_txt;
    private EditText password_txt;
    private Button btn_login;
    private Button btn_cancle;
    private String username;
    private String password;


    @SuppressLint({"MissingInflatedId", "WrongViewCast"})
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_login11);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


//        实现动图
      ImageView image_view=  findViewById((R.id.imageView));
      Glide.with(this).asGif().load(R.drawable.longm).into(image_view);

        username_txt = findViewById(R.id.textView_Uer);
        password_txt = findViewById(R.id.textView_pass);

        btn_login = findViewById(R.id.button_login);
        btn_cancle = findViewById(R.id.button_cancle);

        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                username = username_txt.getText().toString();
                password = password_txt.getText().toString();

                if(username.equals("qq")&&password.equals("123123")){
                    Toast.makeText(getApplicationContext(),"恭喜成功登录",Toast.LENGTH_LONG).show();
                    Intent intent=new Intent(getApplicationContext(),Btns.class);
                    startActivity(intent);

                    username_txt.setText(" ");
                    password_txt.setText(" ");

                }
                if(!username.equals("qq")&&password.equals("123123")){
                    Toast.makeText(getApplicationContext(),"用户名错误，请重新输入",Toast.LENGTH_LONG).show();
                    username_txt.setText("");
                    username_txt.requestFocus();

                }
                if(username.equals("qq")&&!password.equals("123123")){
                    Toast.makeText(getApplicationContext(),"密码错误，请重新输入",Toast.LENGTH_LONG).show();
                    password_txt.setText("");
                    password_txt.findFocus();

                }
                if(!username.equals("qq")&&!password.equals("123123")){
                    Toast.makeText(getApplicationContext(),"用户名，密码均错误，请重新输入",Toast.LENGTH_LONG).show();
                    username_txt.setText("");
                    username_txt.requestFocus();
                    password_txt.setText("");
                    password_txt.findFocus();



                }
            }
        });

    }
}